#pragma once

extern "C"{
#include "stdint.h"
#include "avcodec.h"
#include "avformat.h"
#include "fifo.h"
#include "avstring.h"
#include "swscale.h"

}

class CSetting
{
public:
	int i_audio_channels;
	int i_audio_sample_rate;
	int i_video_width;
	int i_video_height;
	int i_frame_pix_fmt;
	float i_frame_aspect_ratio;


	char* outputfile;

	bool video_disable; //0
	bool audio_disable; //0
	int thread_count; //1
	int audio_codec_tag; //0
	int audio_channels; // 2
	int audio_sample_rate;
	CodecID audio_codec_id;

	int video_codec_tag;//0
	int video_global_header;
	CodecID video_codec_id;
	AVRational frame_rate;
	int video_width;
	int video_height;
	float frame_aspect_ratio;
	PixelFormat frame_pix_fmt;
	int intra_only;
protected:

private:
};



class CMpcEncoder
{
public:
	CMpcEncoder(void);
	~CMpcEncoder(void);

public:
	bool Init(CSetting* pSetting);
	bool EncodeAudio(unsigned char* buf, int size);
	bool EncodeVideo(AVFrame* inFrame, int *frameSize);
	void FinishEncode();

private:
	bool outPutFile();
	bool newAudioStream();
	bool newVideoStream();
	void destoryResource();
	 

private:
	CSetting* m_pSetting;
	AVOutputFormat *	m_pFileOutFormat;
	AVFormatContext*	m_pFormatContext;
	
	AVStream* m_pAudioStream;		
	int m_nAudioFifoSize;
	int m_nAudioRawSize;
	uint8_t* m_pAudioRawBuf;	//use for after encode
	uint8_t* m_pAudioFifoBuf;   //use for resample and input to fifo
	int m_nApts;
	AVFifoBuffer* fifo;
	ReSampleContext* m_pAudioReCtx;

	AVStream* m_pVideoStream;	
	int m_nVideoRawSize;
	uint8_t* m_pVideoRawBuf;	
	AVFrame* m_pResampleFrame;	
	int m_nVpts;
	SwsContext* m_pImageReCtx;	
};
